/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:马星俊
 */

import React, {FC} from "react";
import styles from "@/pages/sys/role/components/Authorize.less";
import {Tree} from "antd";
import permissionService from "@/pages/sys/permission/service";
import useLoad from "@/hooks/useLoad";

interface DeptProps {
  /** 数据主键 */
  primaryKey?: string;
}


const Dept: FC<DeptProps> = (props) => {
  const {primaryKey} = props;
  const {data: members = []} = useLoad<any>({
    isLoad: Boolean(primaryKey),
    onLoad: () => permissionService.saveRoleDept(primaryKey)
  }, [primaryKey]);

  return (
    <div style={{margin: '0 24px 0 0'}}>
      {members.deptScope ? (
        <>
          <div
            className={`${styles.alert} ${styles.warning} ${styles.margin} ${styles.padding}`}>{members.deptScope}</div>
          {members.data ? (
            <Tree
              style={{padding: "10px 5px", overflowY: 'auto'}}
              showIcon
              defaultExpandAll
              treeData={members.data}
            />
          ) : null}
        </>) : (<div className={`${styles.alert} ${styles.warning} ${styles.margin} ${styles.padding}`}>未设置</div>)}
    </div>
  )
}

export default Dept;
